﻿using System;
using System.Collections;
using System.Collections.Generic;
using FlurentFiltration.Visitors;

namespace FlurentFiltration
{
    public static class Filter
    {
        private static FilterBinding _binding;

        static Filter()
        {
            _binding = new FilterBinding();
        }
        
        public static IEnumerable<T> Filtrate<T>(this IEnumerable<T> set, IFilter filter)
            where T : class
        {
            var visitor = new FilterVisitor(_binding);
            return visitor.Visit(set, filter);
        }

        public static void Reset()
        {
            _binding = new FilterBinding();
        }

        public static IFilterBinding CreateBinding()
        {
            return _binding;
        }

        public static IFilterBinding Bind<TCollection, TFilter>(this IFilterBinding binding)
          where TCollection : IEnumerable
        {
            binding.Bind(typeof(TCollection), typeof(TFilter));
            return binding;
        }

        public static IFilterBinding Bind<TCollection, TFilter>()
         where TCollection : IEnumerable
        {
            _binding.Bind(typeof(TCollection), typeof(TFilter));
            return _binding;
        }

        public static IFilterBinding Remove(this IFilterBinding binding, Type tCollection)
        {
            binding.Remove(tCollection);
            return binding;
        }

    }
}
